package working.collection;

public class VolatileTest {


    private int i = 0;

    public static void main(String[] args) {
        VolatileTest volatileTest = new VolatileTest();
        new Thread(() -> {
            while (volatileTest.i < 3){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("volatileTest.i < 3=====：" + volatileTest.i);
            }
            System.out.println("volatileTest.i >= 3=======：" + volatileTest.i);
        }).start();

        new Thread(() -> {
            while (true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                volatileTest.i ++;
                System.out.println("volatileTest.i=====：" + volatileTest.i);
            }
        }).start();
    }

}
